package azure

import (
	httpUtil "app/pkg/http"
	"encoding/json"
	"fmt"

	"github.com/sashabaranov/go-openai"
)

type AzureOpenaiClient struct{}

func NewAzureOpenaiClient() *AzureOpenaiClient { return &AzureOpenaiClient{} }

type Request struct {
	Messages []openai.ChatCompletionMessage `json:"messages"`
}

func (m *AzureOpenaiClient) CreateCompletion(req Request, baseUrl, version, key string) (response openai.ChatCompletionResponse, err error) {
	res, err := httpUtil.JsonPost(
		fmt.Sprintf("%s/openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=%s", baseUrl, version), req,
		map[string]string{"api-key": key}, 20,
	)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(string(res))
		err = json.Unmarshal(res, &response)
	}
	return
}
